/**
 * 
 */
package com.pmsco.pms.util;

import com.pmsco.pms.core.dao.PmsSysInformationDao;
import com.pmsco.pms.core.domain.PmsSysInformation;

/**
 * @author Long Tran
 *
 */
public class PmsSysInfo {
	private static PmsSysInfo instance = null;
	private static PmsSysInformationDao pmsSysInformationDao;
	private static String sysEmailUser;
	private static String sysEmailPassword;
	private static String sysEmailAuth;
	private static String sysEmailTlsEnable;
	private static String sysEmailHost;
	private static Integer sysEmailPort;
	private static Integer sysEncodeType;
	private static String sysLogLevel;
	private static PmsEncoder pmsEncoder;
	
	private PmsSysInfo() {
	}
	
	public static PmsSysInfo getInstance() {
		if(instance == null)
			instance = new PmsSysInfo();
		PmsSysInformation pmsSysInformation = pmsSysInformationDao.getPmsSysInformation();
		setData(pmsSysInformation);
		return instance;
	}
	
	public void initOrReloadInstance() {
		PmsSysInformation pmsSysInformation = pmsSysInformationDao.getPmsSysInformation();
		setData(pmsSysInformation);
	}
	
	private static void setData(PmsSysInformation pmsSysInformation) {
		sysEmailUser = pmsSysInformation.getSysEmailUser();
		sysEmailPassword = pmsSysInformation.getSysEmailPassword();
		sysEmailAuth = pmsSysInformation.getSysEmailAuth();
		sysEmailTlsEnable = pmsSysInformation.getSysEmailTlsEnable();
		sysEmailHost = pmsSysInformation.getSysEmailHost();
		sysEmailPort = pmsSysInformation.getSysEmailPort();
		sysEncodeType = pmsSysInformation.getSysEncodeType();
		sysLogLevel = pmsSysInformation.getSysLogLevel();
		pmsEncoder = PmsEncoderFactory.getEncoder(sysEncodeType);
	}
	
	/**
	 * @param pmsSysInformationDao the pmsSysInformationDao to set
	 */
	public static void setPmsSysInformationDao(PmsSysInformationDao pmsSysInformationDao) {
		PmsSysInfo.pmsSysInformationDao = pmsSysInformationDao;
	}

	/**
	 * @return the sysEmailUser
	 */
	public String getSysEmailUser() {
		return sysEmailUser;
	}

	/**
	 * @return the sysEmailPassword
	 */
	public String getSysEmailPassword() {
		return sysEmailPassword;
	}

	/**
	 * @return the sysEmailAuth
	 */
	public String getSysEmailAuth() {
		return sysEmailAuth;
	}

	/**
	 * @return the sysEmailTlsEnable
	 */
	public String getSysEmailTlsEnable() {
		return sysEmailTlsEnable;
	}

	/**
	 * @return the sysEmailHost
	 */
	public String getSysEmailHost() {
		return sysEmailHost;
	}

	/**
	 * @return the sysEmailPort
	 */
	public Integer getSysEmailPort() {
		return sysEmailPort;
	}

	/**
	 * @return the sysEncodeType
	 */
	public Integer getSysEncodeType() {
		return sysEncodeType;
	}

	/**
	 * @return the sysLogLevel
	 */
	public String getSysLogLevel() {
		return sysLogLevel;
	}

	/**
	 * @return the pmsEncoder
	 */
	public PmsEncoder getPmsEncoder() {
		return pmsEncoder;
	}

	/**
	 * @return the pmsSysInformationDao
	 */
	public static PmsSysInformationDao getPmsSysInformationDao() {
		return pmsSysInformationDao;
	}

	/**
	 * @param instance the instance to set
	 */
	public static void setInstance(PmsSysInfo instance) {
		PmsSysInfo.instance = instance;
	}
}
